﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using School.Entities;

namespace School.Pages.Teaching
{
    public partial class TE_Show_Question : System.Web.UI.Page
    {
        private static SchoolEntities db = new SchoolEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
                FillControls();
        }
        private void FillControls()
        {
            ddlCampus.DataSource = School.Uniform.PayOrder.AllCampus();
            ddlCampus.DataBind();
        }
        private void ddlBind(DropDownList ddl)
        {
            ddl.Items.Clear();
            ddl.Items.Insert(0, new ListItem("اختيار", "0"));
            ddl.DataBind();
        }
        protected void ddlCertificate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCertificate.SelectedValue != "0")
            {
                ddlStadge.DataSource = School.Uniform.PayOrder.GetStadgeByCertificate(int.Parse(ddlCertificate.SelectedValue));
                ddlBind(ddlStadge);
            }

        }
        protected void ddlStadge_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlStadge.SelectedValue != "0")
            {
                ddlGrade.DataSource = School.Uniform.PayOrder.GetGradeByStadge(int.Parse(ddlStadge.SelectedValue));
                ddlBind(ddlGrade);
            }

        }
        protected void ddlCampus_TextChanged(object sender, EventArgs e)
        {
            if (ddlCampus.SelectedValue != "0")
            {

                ddlCertificate.DataSource = School.Uniform.PayOrder.GetCertificateByCamp(int.Parse(ddlCampus.SelectedValue));
                ddlBind(ddlCertificate);
                //DropDownList1
                // ddlBind(DropDownList1, School.Service.Bus.GetBusByCamp(Convert.ToInt32(ddlCampus.SelectedValue.ToString())).ToList());
            }
        }
        protected void ddlGrade_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlGrade.SelectedValue != "0")
            {
                ddlstudent.DataSource = School.Service.Bus.AllFullName_Notinbus(Convert.ToInt32(ddlCampus.SelectedValue), Convert.ToInt32(ddlCertificate.SelectedValue), Convert.ToInt32(ddlStadge.SelectedValue), int.Parse(ddlGrade.SelectedValue));
                ddlBind(ddlstudent);
            }
        }
        private void ddlBind(DropDownList ddl, object o)
        {
            ddl.DataSource = o;
            ddl.Items.Clear();
            ddl.Items.Insert(0, new ListItem("اختيار", "0"));
            ddl.DataBind();
        }

        protected void ddlstudent_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlstudent.SelectedIndex > 0)
            {

                ddlBind(ddlSubjects, School.Teaching.Teaching.Get_Subject_ByStud_id(31));

            }
        }

        protected void ddlSubjects_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlSubjects.SelectedIndex > 0)
            {
                ddlBind(ddlCourse, School.Teaching.Teaching.Get_Course_By_Subject(Convert.ToInt32(ddlSubjects.SelectedValue)));
            }
        }

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            if (ddlCourse.SelectedIndex > 0)
            {
                gvBank_QinBind();
            }
        }

        private void gvBank_QinBind()
        {
            gvBank_Qin.DataSource = School.Teaching.Teaching.Get_Topic_Q_inAnswer(Convert.ToInt32(ddlCourse.SelectedValue));
            gvBank_Qin.DataBind();
        }
        protected void gvBank_Qin_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvBank_Qin.PageIndex = e.NewPageIndex;
            gvBank_QinBind();
        }
    }
}